using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using CSP.Model.CSP;

namespace CSP.DataAccess.Mapping
{
    public class NewsMap : EntityTypeConfiguration<News>
    {
        public NewsMap()
        {
            // Primary Key
            this.HasKey(t => t.id);

            // Properties
            this.Property(t => t.title)
                .HasMaxLength(50);

            this.Property(t => t.keywords)
                .HasMaxLength(100);

            this.Property(t => t.lastmodified)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(8)
                .IsRowVersion();

            // Table & Column Mappings
            this.ToTable("News");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.newsTypeId).HasColumnName("newsTypeId");
            this.Property(t => t.title).HasColumnName("title");
            this.Property(t => t.keywords).HasColumnName("keywords");
            this.Property(t => t.content).HasColumnName("content");
            this.Property(t => t.ishomeShow).HasColumnName("ishomeShow");
            this.Property(t => t.lastmodified).HasColumnName("lastmodified");
            this.Property(t => t.createtime).HasColumnName("createtime");

            // Relationships
            this.HasRequired(t => t.NewsType)
                .WithMany(t => t.News)
                .HasForeignKey(d => d.newsTypeId);

        }
    }
}
